home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Science / µSim 1.0b5 folder / Libs / Utils6.c < prev    next >
Encoding:
Text File  |  1994-07-27  |  3.5 KB  |  141 lines  |  [TEXT/MMCC]

  1. /*
  2. Copyright © 1993,1994 by Fabrizio Oddone
  3. ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
  4. This source code is distributed as freeware: you can copy, exchange, modify this
  5. code as you wish. You may include this code in any kind of application: freeware,
  6. shareware, or commercial, provided that full credits are given.
  7. You may not sell or distribute this code for profit.
  8. */
  9.  
  10.  
  11. //#pragma load "MacDump"
  12.  
  13. #include    "Utils6.h"
  14.  
  15. #if !defined(powerc) && !defined (__powerc)
  16.  
  17. typedef struct {
  18.     FSSpec    destFile;
  19.     ScriptCode    theScript;
  20.     } StdFileResult, *StdFileResultPtr;
  21.  
  22. #if    !defined(FabNoSegmentDirectives)
  23. #pragma segment Registration
  24. #endif
  25.  
  26. short FabFSpOpenResFile(const FSSpec *spec,char permission)
  27. {
  28. long    Gresp;
  29. register Boolean    flag = false;
  30.  
  31. if (Gestalt(gestaltFSAttr, &Gresp) == noErr)
  32.     if (Gresp & (1L << gestaltHasFSSpecCalls))
  33.         flag = true;
  34.  
  35. return (flag ?
  36.         FSpOpenResFile(spec, permission) :
  37.         HOpenResFile(spec->vRefNum, spec->parID, spec->name, permission));
  38. }
  39.  
  40. OSErr FabFSpOpenDF(const FSSpec *spec,char permission,short *refNum)
  41. {
  42. long    Gresp;
  43. register Boolean    flag = false;
  44.  
  45. if (Gestalt(gestaltFSAttr, &Gresp) == noErr)
  46.     if (Gresp & (1L << gestaltHasFSSpecCalls))
  47.         flag = true;
  48.  
  49. return (flag ?
  50.         FSpOpenDF(spec, permission, refNum) :
  51.         HOpen(spec->vRefNum, spec->parID, spec->name, permission, refNum));
  52. }
  53.  
  54. OSErr FabFSpCreate(const FSSpec  *spec,OSType creator,OSType fileType, ScriptCode scrTag)
  55. {
  56. long    Gresp;
  57. register Boolean    flag = false;
  58.  
  59. if (Gestalt(gestaltFSAttr, &Gresp) == noErr)
  60.     if (Gresp & (1L << gestaltHasFSSpecCalls))
  61.         flag = true;
  62.  
  63. return (flag ?
  64.         FSpCreate(spec, creator, fileType, scrTag) :
  65.         HCreate(spec->vRefNum, spec->parID, spec->name, creator, fileType));
  66. }
  67.  
  68. OSErr FabFSpDelete(const FSSpec *spec)
  69. {
  70. long    Gresp;
  71. register Boolean    flag = false;
  72.  
  73. if (Gestalt(gestaltFSAttr, &Gresp) == noErr)
  74.     if (Gresp & (1L << gestaltHasFSSpecCalls))
  75.         flag = true;
  76.  
  77. return (flag ?
  78.         FSpDelete(spec) :
  79.         HDelete(spec->vRefNum, spec->parID, spec->name));
  80. }
  81.  
  82. void FabStandardGetFile(FileFilterUPP fileFilter, short numTypes, SFTypeList typeList,
  83.                             StandardFileReply *reply)
  84. {
  85. Point    mypt = {90, 10};
  86. long    Gresp;
  87. register Boolean    flag = false;
  88.  
  89. if (Gestalt(gestaltStandardFileAttr, &Gresp) == noErr)
  90.     if (Gresp & (1L << gestaltStandardFile58))
  91.         flag = true;
  92.  
  93. if (flag) {
  94.     StandardGetFile(fileFilter, numTypes, typeList, reply);
  95.     }
  96. else {
  97.     SFReply    myOldReply;
  98.  
  99.     SFGetFile(mypt, nil, fileFilter, numTypes, typeList, nil, &myOldReply);
  100.     reply->sfGood = myOldReply.good;
  101. //    reply->sfReplacing = false;
  102.     reply->sfType = myOldReply.fType;
  103.     reply->sfFile.vRefNum = myOldReply.vRefNum;
  104.     reply->sfFile.parID = LMGetCurDirStore();
  105.     (void) PLstrcpy(reply->sfFile.name, myOldReply.fName);
  106.     reply->sfScript = smCurrentScript;
  107.     }
  108. }
  109.  
  110. void FabStandardPutFile(ConstStr255Param prompt,
  111.                             ConstStr255Param defaultName,
  112.                             StandardFileReply *reply)
  113. {
  114. Point    mypt = {90, 10};
  115. long    Gresp;
  116. register Boolean    flag = false;
  117.  
  118. if (Gestalt(gestaltStandardFileAttr, &Gresp) == noErr)
  119.     if (Gresp & (1L << gestaltStandardFile58))
  120.         flag = true;
  121.  
  122. if (flag) {
  123.     StandardPutFile(prompt, defaultName, reply);
  124.     }
  125. else {
  126.     SFReply    myOldReply;
  127.  
  128.     SFPutFile(mypt, prompt, defaultName, nil, &myOldReply);
  129.     reply->sfGood = myOldReply.good;
  130.     reply->sfReplacing = false;
  131.     reply->sfType = myOldReply.fType;
  132.     reply->sfFile.vRefNum = myOldReply.vRefNum;
  133.     reply->sfFile.parID = LMGetCurDirStore();
  134.     (void) PLstrcpy(reply->sfFile.name, myOldReply.fName);
  135.     reply->sfScript = smCurrentScript;
  136.     }
  137. }
  138.  
  139. #endif
  140.  
  141.